package com.ftx.controller.test.annotation.value;

import com.ftx.controller.test.annotation.beans.MainConfigBeans;
import com.ftx.domain.vo.PersonVo;
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;

/**
 * Created by fengtingxin on 2020/4/15.
 */
public class IOCTtest_PropertyValue {



    @Test
    public void testImport(){
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(MainConfigPropertyValues.class);
        System.out.println("容器创建完成");
        printBeans(applicationContext);
        Person personVo = applicationContext.getBean(Person.class);
        System.out.println(personVo);

        ConfigurableEnvironment environment = applicationContext.getEnvironment();
        String property = environment.getProperty("person.nickName");
        System.out.println(property);

    }

    private void printBeans(AnnotationConfigApplicationContext applicationContext){
        String[] names = applicationContext.getBeanDefinitionNames();
        for ( String name : names){
            System.out.println(name);
        }

    }
}
